﻿using System;
using System.Net.Sockets;

namespace Mozi.HttpEmbedded
{
    public delegate void ServerStart(object sender, ServerArgs args);

    public delegate void ServerStop(object sender, ServerArgs args);

    public delegate void ClientDisConnect(object sender, ClientConnectArgs ars);

    public delegate void ClientConnect(object sender, ClientConnectArgs args);

    public delegate void ReceiveStart(object sender, DataTransferArgs args);

    public delegate void ReceiveEnd(object sender, DataTransferArgs args);
    /// <summary>
    /// 数据报文传递回调
    /// </summary>
    /// <param name="host">主机地址</param>
    /// <param name="port">主机端口</param>
    /// <param name="data">字节流</param>
    public delegate void DatagramReceive(string host, int port, byte[] data);
    /// <summary>
    /// 服务器事件参数
    /// </summary>
    public class ServerArgs : EventArgs
    {
        /// <summary>
        /// 绑定端口
        /// </summary>
        public int BindPort { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StartTime { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime StopTime { get; set; }
    }
    /// <summary>
    /// 服务端连接事件参数
    /// </summary>
    public class ClientConnectArgs : EventArgs
    {
        /// <summary>
        /// 会话标识符
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 远端IP地址
        /// </summary>
        public string IP { get; set; }
        /// <summary>
        /// 远端端口
        /// </summary>
        public int RemotePort = 0;

        /// <summary>
        /// 连接时间  
        /// </summary>  
        public DateTime ConnectTime { get; set; }

        private Socket _socket;

        public Socket Client
        {
            get { return _socket; }
            set { _socket = value; }
        }
    }
    /// <summary>
    /// 
    /// </summary>
    public class DataTransferArgs : EventArgs
    {
        /// <summary>
        /// 会话标识符
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 缓存的数据
        /// </summary>
        public byte[] Data { get; set; }
        /// <summary>
        /// 源地址IPV4
        /// </summary>
        public string IP { get; set; }
        /// <summary>
        /// 客户端端口
        /// </summary>
        public int Port { get; set; }
        public Socket Socket { get; set; }
        public StateObject State { get; set; }

        ~DataTransferArgs()
        {
            Data = null;
            State = null;
        }
    }
    /// <summary>
    /// 客户端访问事件参数
    /// </summary>
    public class ClientAccessArgs : EventArgs
    {
        /// <summary>
        /// 会话标识符
        /// </summary>
        public string Id { get; set; }
        public string Path { get; set; }
        public string Query { get; set; }
        public string IP { get; set; }
        public int StatusCode { get; set; }
        public string Message { get; set; }
    }
}
